<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use kartik\file\FileInput;
use kartik\select2\Select2;
use yii\web\JsExpression;
use app\common\Functions;

/* @var $this yii\web\View */
/* @var $model \yii2mod\rbac\models\BizRuleModel */
/* @var $form ActiveForm */
?>

<div class="rule-item-form">

    <?php $form = ActiveForm::begin(); ?>

        <?php

        echo  $form->field($model, 'id',['labelOptions'=>['style'=>'display:none']])->hiddenInput(['value' => $model->id]);


        //echo  $form->field($model, 'cust_type_id',['labelOptions'=>['style'=>'display:none']])->hiddenInput(['value' => $attr_type_spec_id]);

        if ($model->object_type_id==1)
        {
            echo  $form->field($model, 'object_id',['labelOptions'=>['style'=>'display:none']])->hiddenInput(['value' => $cust_id]);
        }
        else
        {
            echo  $form->field($model, 'object_id',['labelOptions'=>['style'=>'display:none']])->hiddenInput(['value' => $prod_id]);
        }


        echo  $form->field($model, 'object_type_id',['labelOptions'=>['style'=>'display:none']])->hiddenInput(['value' => $model->object_type_id]);




        if ($update)
        {
            echo $form->field($model, "order_type_id")->label('订单类型');
        }
        else
        {
            echo $form->field($model, "order_type_id")->label('订单类型')->dropDownList( ArrayHelper::map($orderTypes, 'order_type_id', 'type_name'),
                [
                    'prompt'=>'--请选择生成订单的类型--',


                ]);
        }


        echo $form->field($model, "state")->label($prodAttr->attr_spec_name)->dropDownList(Functions::getDomains('order','state'));


        $orderStaffIDStyles = [];
        //  Yii::trace("@@@@@@@@@-----------@@@@@@@@@@@");
        if ($model->staffName)
        {

            //Yii::trace($model->orderStaffName);
            $orderStaffIDStyles['initValueText'] = $model->staffName;
            // $parentStyles['value'] = $model->parentProdName;
        }

        $orderStaffIDStyles['options'] = ['placeholder' => '请选择 ...'];

        $orderStaffIDStyles['pluginOptions'] = [
            'placeholder' => '查询 ...',
            'allowClear' => true,
            'minimumInputLength' => 1,
            'language' => [
                'errorLoading' => new JsExpression("function () { return '稍等...'; }"),
            ],
            'ajax' => [
                'url' => '/prod/prodinst/seachorderstaff',
                'dataType' => 'json',
                'data' => new JsExpression('function(params) { return {q:params.term}; }')
            ],
            'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
            'templateResult' => new JsExpression('function(res) { 
            
            return res.text; }'),



            'templateSelection' => new JsExpression('function (res) { 
                      
                     
                    return res.text; }')];
        echo $form->field($model, 'staff_id')->label( '订单追踪人')->widget(Select2::classname(), $orderStaffIDStyles);


        echo  $form->field($model, 'remark')->label( $prodSpecName . '订单备注')->textInput(['maxlength' => 64]);



        ?>

    <?php

    foreach ($orderAttrSpecs as $attrSpec)
    {
        $orderAttr = $attrSpec->attrSpecs;

        // 文件
        if ($orderAttr->attr_spec_type_id==2)
        {
            $pluginOptions=[];
            $pluginOptions['initialPreviewAsData'] = true;
            $pluginOptions['showRemove'] = true;
            $pluginOptions['showUpload'] = false;

            if ($update)
            {
                $pluginOptions['initialPreview'] = $p1[$orderAttr->attr_spec_id];
            }

            // echo $form->field($uploadModel, "file[]")->label($orderAttr->attr_spec_name)->widget(FileInput::classname(), [
            //attrSpec[{$orderAttr->attr_spec_id}][content]
            echo $form->field($uploadModel, "file[{$orderAttr->attr_spec_id}][]")->label($orderAttr->attr_spec_name)->widget(FileInput::classname(), [
                'options' => ['multiple' => false],
                'pluginOptions' =>$pluginOptions,
            ])->fileInput();
        }
        elseif ($orderAttr->attr_spec_type_id==3) // 如果type等于3 需要进行字符转义
        {  ?>
            <div class="col-md-6">
                <?php  echo $form->field($model, "localAttrsInsts[{$orderAttr->attr_spec_id}][content]")->label($orderAttr->attr_spec_name)->dropDownList(Functions::getDomains('attr_spec',$orderAttr->attr_spec_id));?>
            </div>

            <?php

        }
        else
        {
            ?>
            <div class="col-md-6">
                <?php  echo $form->field($model, "localAttrsInsts[{$orderAttr->attr_spec_id}][content]" )->label($orderAttr->attr_spec_name)->textInput(['maxlength' => 64]);  ?>
            </div>

        <?php }

        echo $form->field($model, "localAttrsInsts[{$orderAttr->attr_spec_id}][attrSpecTypeID]",['labelOptions'=>['style'=>'display:none']])->hiddenInput(['value' => $orderAttr->attr_spec_type_id]);


    }


        ?>





        <?php


        //echo $form->field($model, 'region_type_id')->label('区域类型')->textInput();
        ?>




    <div class="form-group">
        <?php echo Html::submitButton($model->getIsNewRecord() ? Yii::t('region', 'Create') : Yii::t('region', 'Update'), [
            'class' => $model->getIsNewRecord() ? 'btn btn-success' : 'btn btn-primary', ]); ?>
        <?php echo Html::a(Yii::t('region', 'Cancel'), Yii::$app->request->getReferrer(), ['class' => 'btn btn-default']); ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>

